package pl.edu.agh.iosr.gamblingzone.dao.hibernate;

import java.util.Collection;

import org.hibernate.criterion.Restrictions;

import pl.edu.agh.iosr.gamblingzone.dao.MoneyVoucherDAO;
import pl.edu.agh.iosr.gamblingzone.model.MoneyVoucher;
import pl.edu.agh.iosr.gamblingzone.model.User;

/**
 * The Class MoneyVoucherDAOBean.
 */
public class MoneyVoucherDAOBean extends GenericDAOBean<MoneyVoucher, Long> implements MoneyVoucherDAO {

	/* (non-Javadoc)
	 * @see pl.edu.agh.iosr.gamblingzone.dao.MoneyVoucherDAO#findAll(pl.edu.agh.iosr.gamblingzone.model.User, int)
	 */
	public Collection<MoneyVoucher> findAll(User user, int page) {
		return findByCriteria(new ComplexCriterion().add(Restrictions.like("owner", user)), page);
	}

	/* (non-Javadoc)
	 * @see pl.edu.agh.iosr.gamblingzone.dao.MoneyVoucherDAO#getEntitiesCount(pl.edu.agh.iosr.gamblingzone.model.User)
	 */
	public int getEntitiesCount(User u) {
		return getEntitiesCount(new ComplexCriterion().add(Restrictions.like("owner", u)));
	}

	/* (non-Javadoc)
	 * @see pl.edu.agh.iosr.gamblingzone.dao.MoneyVoucherDAO#findAllActive(pl.edu.agh.iosr.gamblingzone.model.User, int)
	 */
	public Collection<MoneyVoucher> findAllActive(User user, int page) {
		return findByCriteria(new ComplexCriterion()
				.add(Restrictions.like("owner", user))
				.add(Restrictions.isNotNull("active")), page);
	}

	/* (non-Javadoc)
	 * @see pl.edu.agh.iosr.gamblingzone.dao.MoneyVoucherDAO#getActiveEntitesCount(pl.edu.agh.iosr.gamblingzone.model.User)
	 */
	public int getActiveEntitesCount(User u) {
		return getEntitiesCount(new ComplexCriterion()
			.add(Restrictions.like("owner", u))
			.add(Restrictions.isNotNull("active")));
	}
}
